package com.bank.common.stringUtil;

import com.google.gson.Gson;

import java.util.HashMap;
import java.util.Map;

/**
 * The type String util.
 *
 * @author Cejay1314
 * @version 1.0
 * @create 2023 /2/17 18:28
 */
public class StringUtil {
    private static StringUtil target;
    /**
     * The Gson.
     */
    Gson gson;

    /**
     * Instantiates a new String util.
     */
    public StringUtil(){
        gson = new Gson();
    }

    /**
     * Get instance string util.
     *
     * @return the string util
     */
    public static StringUtil getInstance(){
        if(target==null) target = new StringUtil();
        return target;
    }

    /**
     * String transform into map map.
     *
     * @param body the body
     * @return the map
     */
    public Map<String,Object> stringTransformIntoMap(String body){
        Map<String, Object> map = new HashMap<String, Object>();
        map = gson.fromJson(body, map.getClass());
        return map;
    }

    /**
     * String transform into map string map.
     *
     * @param body the body
     * @return the map
     */
    public Map<String,String> stringTransformIntoMapString(String body){
        Map<String, String> map = new HashMap<String, String>();
        map = gson.fromJson(body, map.getClass());
        return map;
    }

    public static Double sub(String a,String b){
        return Double.parseDouble(a) - Double.parseDouble(b);
    }
    public static Double sub(Double a,String b){
        return a - Double.parseDouble(b);
    }
    public static Double sub(String a,Double b){
        return Double.parseDouble(a) - b;
    }

    public static Double add(String a,String b){
        return Double.parseDouble(a) + Double.parseDouble(b);
    }
    public static Double add(Double a,String b){
        return a + Double.parseDouble(b);
    }
    public static Double add(String a,Double b){
        return Double.parseDouble(a) + b;
    }
}

